package com.bsh.serviceImpl;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import com.bsh.dto.HOrderListQryDto;
import com.bsh.repository.DaoHOrder;
import com.bsh.service.HOrderService;
import com.bsh.utils.Pager;

/** 
 *
 *酒店订单
 * @author  kms 
 * @version 1.0  
 */
@Service
@Transactional
public class HOrderServiceImpl implements HOrderService {
	private static Logger log = LoggerFactory.getLogger(HOrderServiceImpl.class);
	@Autowired
	DaoHOrder orderDao;
	
	/**
	 * 订单列表
	 */
	@Override
	public List<Map<String, Object>> getPage(Pager pager, HOrderListQryDto qryParam) {
		StringBuilder where = new StringBuilder();
		if (qryParam != null) {
			if (!StringUtils.isEmpty(qryParam.getHotelId())) {
				where.append(String.format(" and hh.id=%d ",qryParam.getHotelId()));
			}
			if (!StringUtils.isEmpty(qryParam.getStatus())) {
				where.append(String.format(" and o.status=%d ", qryParam.getStatus()));
			}
			if (!StringUtils.isEmpty(qryParam.getIsPaid())) {
				where.append(String.format(" and od.is_paid=%d ", qryParam.getIsPaid()));
			}
			
			if (!StringUtils.isEmpty(qryParam.getOrderNum())) {
				where.append(String.format(" and od.order_num like '%%%s%%' ", qryParam.getOrderNum().trim()));
			}
			if (!StringUtils.isEmpty(qryParam.getInTimeMin())) {
				where.append(String.format(" and od.in_time >='%s' ", qryParam.getInTimeMin().trim()));
			} 
			if (!StringUtils.isEmpty(qryParam.getInTimeMax())) {
				where.append(String.format(" and od.in_time <='%s 23:59:59' ", qryParam.getInTimeMax().trim()));
			}
			
		}
		StringBuilder order = new StringBuilder();
		
		List<Map<String, Object>> list = orderDao.getPage(pager, where.toString(),order.toString());
		return list;
	}

}
